package org.example.demo3.server.Controller;

import lombok.extern.slf4j.Slf4j;
import org.example.demo3.common.result.PageResult;
import org.example.demo3.common.result.Result;
import org.example.demo3.pojo.dto.RoomDeleteDTO;
import org.example.demo3.pojo.dto.RoomPageQueryDTO;
import org.example.demo3.pojo.dto.RoomRegisterDTO;
import org.example.demo3.pojo.dto.RoomStatusDTO;
import org.example.demo3.pojo.vo.RoomVO;
import org.example.demo3.server.service.ChatRoomMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private ChatRoomMessageService chatRoomMessageService;

    @PostMapping("/register")
    public Result<RoomRegisterDTO> roomRegister(@RequestBody RoomRegisterDTO roomRegisterDTO){
        log.info("name:{} begin to register",roomRegisterDTO.getHostName());
        log.info("roomName:{},hostName:{},password:{}",roomRegisterDTO.getName(),roomRegisterDTO.getHostName(),roomRegisterDTO.getPassword());
        chatRoomMessageService.roomRegister(roomRegisterDTO);
        return Result.success();
    }

    @GetMapping("/page")
    public Result<PageResult> roomPageQuery(RoomPageQueryDTO roomPageQueryDTO){
            log.info("start to query...{}",roomPageQueryDTO);
            PageResult pageResult=chatRoomMessageService.roomPageQuery(roomPageQueryDTO);
            return Result.success(pageResult);
    }

    /**
     * 更改房间状态
     * @param status
     * @param roomStatusDTO
     * @return
     */
    @PostMapping("/status/{status}")
    public Result roomStatusUpdate(@PathVariable Integer status, @RequestBody RoomStatusDTO roomStatusDTO){
        log.info("begin to update id:{},status:{},hostName:{}",roomStatusDTO.getRoomId(),status,roomStatusDTO.getHostName());
        chatRoomMessageService.roomStatusUpdate(status,roomStatusDTO.getRoomId(),roomStatusDTO.getHostName());
        return Result.success();
    }

    @GetMapping("/name")
    public Result<RoomVO> roomNameQuery(String roomId){
        log.info("begin to select roomName by roomId");
        RoomVO roomVO=chatRoomMessageService.roomNameQuery(roomId);
        return Result.success(roomVO);
    }

    @PostMapping("/delete")
    public Result roomDelete(@RequestBody RoomDeleteDTO roomDeleteDTO){
        log.info("begin to delete room...");
        chatRoomMessageService.roomDelete(roomDeleteDTO.getRoomId());
        return Result.success();
    }



}
